package Factory;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/6/24 14:21
 * 说明：静态工厂 6月24日手写复习一遍
 *
 */

public class SimpleFactory_Again {

    public static AbstractProduct createProduct(String type){
        AbstractProduct abstractProduct;
        if (type.equals("A")) abstractProduct = new ProA();
        else if (type.equals("B")) abstractProduct = new ProB();
        else if (type.equals("C")) abstractProduct = new ProC();
        else {
            abstractProduct = null;
            System.out.println("No such type of product.");
        }
        return abstractProduct;
    }


    public static void main(String[] args) {
        AbstractProduct abstractProduct = SimpleFactory_Again.createProduct("C");
        abstractProduct.getProduct();
    }
}

abstract class AbstractProduct{
    public abstract void getProduct();
}

class ProA extends AbstractProduct{
    @Override
    public void getProduct(){
        System.out.println("Product A");
    }
}

class ProB extends AbstractProduct{
    @Override
    public void getProduct(){
        System.out.println("Product B");
    }
}

class ProC extends AbstractProduct{
    @Override
    public void getProduct(){
        System.out.println("Product C");
    }
}